/*
 * @Author: czy
 * @Date: 2021-05-19 21:30:58
 * @LastEditTime: 2021-07-15 09:37:54
 */
#ifndef __SYSTEM_H_
#define __SYSTEM_H_

#include "datetime.h"

#include "sys/type.h"

// IO
#define CLS         1
#define GETC        2
#define PUTC        3
#define READ        4
#define WRITE       5
// syscall
void cls(void);
int getc(void);
int putc(int ch);
char *read(char *str, const char *promrt);
int write(char *buf);
// system
int printk(const char *format, ...);

// interrupt
#define TIMER       6
#define SETTIMEOUT  7
#define CANCELTSK   8
#define CLI         9
#define STI         10
// syscall
int timer(void (*func)(void), int interval);
int setTimeout(void (*func)(void), int interval);
void cancelTsk(int tskId);
void cli(void);
void sti(void);

// memory
#define BRK         11
// syscall
void *brk(void);
// system
void *kmalloc(unsigned int size);
void kfree(void *ptr);
void allocblock(unsigned int *heap, unsigned int *stack);
void freeblock(unsigned int heap);

// shell
#define STARTSHELL  12
// syscall
void startShell(void);

// communicate
#define GETTIME     13
#define SETTIME     14
#define GETENV      15
#define SETENV      16
// syscall
void gettime(time_t *time);
void settime(time_t *time);
void *getenv(char *name);
void setenv(char *name, void *value);

// process
#define CREATEPROCESS   17
#define DESTROYPROCESS  18
#define PROCESSSTART    19
#define PROCESSEND      20
// syscall
int createProcess(int (*tskBody)(void));
void destroyProcess(int tskIndex);
void processStart(int tskIndex);
void processEnd(void);
// system
PCB *get_current_process(void);
void schedule(void);
void processSwitch(void);

#endif